use std::collections::BTreeMap;
impl Solution {
    pub fn count_nice_pairs(nums: Vec<i32>) -> i32 {
        let mut map = BTreeMap::new();
        for val in nums {
            let re = Solution::rev(val);
            map.entry(val - re).and_modify(|v| *v += 1).or_insert(1);
        }
        let mut ans = 0i64;
        for (&k, &v) in map.iter() {
            ans += v * (v - 1)/2 ;
            ans %= 1_000_000_000 + 7;
        }
        return (ans ) as i32;
    }
    fn rev(mut num: i32) -> i32 {
        let mut ans = 0;
        while num > 0 {
            ans *= 10;
            ans += num % 10;
            num /= 10;
        }
        ans
    }
}